package com.sdjenkins.test;

import java.io.FileReader;

import java.io.Reader;

import java.util.ArrayList;
import java.util.Collection;

import com.sdjenkins.sms.Collector;
import com.sdjenkins.sms.SmsCore;
import com.sdjenkins.sms.WASms;

import com.sdjenkins.sms.Smses;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.StaxDriver;

public class CollectWa {
	

	private XStream xstream;
    
    public CollectWa() {
    	
 	    xstream = new XStream(new StaxDriver());
		xstream.alias("sms", WASms.class);
		xstream.alias("smses", Smses.class);
		xstream.useAttributeFor(Smses.class, "count");
	
        xstream.useAttributeFor(WASms.class, "when");        
        xstream.useAttributeFor(WASms.class, "address"); 
        xstream.useAttributeFor(WASms.class, "type");
        xstream.useAttributeFor(WASms.class, "body");

        xstream.addImplicitCollection(Smses.class, "sms", WASms.class);
	    
    }
    
    public Collection<Collector> addFromFile(String file) {
    	
    	Smses smses;
    	Collection<Collector> all = new ArrayList<Collector>();
    	try {	
	    	Reader reader = new FileReader(file);
	    	smses = (Smses)xstream.fromXML(reader);
	    	reader.close();

	    	System.out.println(smses.toString());
	    }
	    catch (Exception e) {
	    	throw new RuntimeException(e);
	    }
	    return all;
    }
    

}
